<template>
  <!-- h5登录 -->
  <view class="loginPage">
    <img class="loginBg" src="@/static/image/webApp/loginBg.png" alt="" />
    <view class="contBox">
      <view class="inpBox">
        <input class="textInput" v-model.trim="loginForm.username" placeholder="请输入手机号" />
        <input class="textInput" v-model.trim="loginForm.password" type="password" placeholder="请输入密码" password />
      </view>
      <u-button @click="submitLogin" :loading="loginLoading" loading-text="登录中..." class="btnns" type="primary"> 登录 </u-button>
      <view class="btnHome" @click="gotoIndex">返回首页</view>
    </view>
  </view>
  <!-- 微信小程序授权登录 -->
</template>

<script>
const app = getApp()
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
      },
      loginLoading: false,
    }
  },
  onLoad(options) {
    // if (options.invacationId) {
    //   uni.setStorageSync('invacationId', options.invacationId)
    // } else if (options.scene) {
    //   uni.setStorageSync('invacationId', options.scene)
    // }
    // if (options.inviteType) {
    //   uni.setStorageSync('inviteType', options.inviteType)
    // }
    // this.inteval = setInterval(() => {
    //   let that = this
    //   // 获取用户的登录状态
    //   uni.login({
    //     success(loginRes) {
    //       that.code = loginRes.code
    //     },
    //   })
    // }, 29000)
    // this.invacationId = options.invacationId
  },
  methods: {
    // 获取用户菜单信息
    submitLogin() {
      if (this.loginLoading) return
      if (this.loginForm.username == '') {
        this.$u.toast('用户名不能为空')
        return
      }
      if (this.loginForm.password == '') {
        this.$u.toast('密码不能为空')
        return
      }

      this.loginLoading = true
      this.$https
        .post({
          url: '/axh/dtUsers/loginDtUsers',
          data: {
            phone: this.loginForm.username,
            password: this.loginForm.password,
          },
        })
        .then((res) => {
          // 查询菜单权限
          uni.setStorageSync('accesstoken', res.token)
          uni.setStorageSync('dtUsersVo', JSON.stringify(res.dtUsersVo))
          this.$https.post({ url: '/axh/phone/role' }).then((res) => {
            this.loginLoading = false
            uni.setStorageSync('appRole', JSON.stringify(res.result))
            // this.backHome()
            uni.redirectTo({
              url: '/pageContent/finance/content',
            })
            this.$u.toast('登陆成功，欢迎您')
          })
          this.$https.post({ url: '/axh/indexAccountDetail' }).then((res) => {
            uni.setStorageSync('manageAreaList', res.result.manageAreaList.join('，'))
          })
        })
        .catch((err) => {
          this.loginLoading = false
        })
    },

    // 返回首页
    gotoIndex() {
      uni.redirectTo({
        url: '/pageContent/finance/content',
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.loginPage {
  background-color: #fff;
  position: relative;
}
.loginBg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
}
.contBox {
  box-sizing: border-box;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 0 48rpx;
  .btnHome {
    font-size: 28rpx;
    text-align: center;
    margin-top: 20rpx;
    color: rgb(126, 126, 126);
  }
  .inpBox {
    width: 100%;
    display: flex;
    flex-direction: column;
    padding-top: 470rpx;
    .textInput {
      border: none;
      height: 96rpx;
      border-bottom: 1px solid #eeeeee;
      font-size: 26rpx;
      padding: 0 24rpx;
    }
    .placeholderText {
      font-size: 26rpx;
      color: #c4c4c5;
    }
  }
  .btnns {
    width: 100%;
    background: linear-gradient(120deg, #50a1ec 1%, #2c83e4 59%);
    border-radius: 4px;
    margin-top: 66rpx;
  }
}
</style>
